import Vue from 'vue';
import axios from 'axios';

axios.defaults.baseURL = (() => {
	let url = window.location.protocol + '//' + window.location.host;
	if (process.env.NODE_ENV === 'development') {
		url += '/api';
	}
	return url;
})();

// http请求拦截器
axios.interceptors.request.use(
	config => {
		return config;
	},
	err => {
		return Promise.reject(err);
	}
);

// http响应拦截器
axios.interceptors.response.use(
	response => {
		return response;
	},
	err => {
		return Promise.reject(err);
	}
);

Vue.prototype.$http = axios;
Vue.prototype.$defaultBaseUrl = axios.defaults.baseURL;
